package com.aijk.web.admin.utils;

import com.aijk.commons.lang.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author zhangjh
 * @date 2017/5/2
 */
public class ConvertUtil {

    public static List<Integer> convertToList(String strIds){
        List<Integer> idList = new ArrayList<>();
        if (StringUtil.isNotBlank(strIds)){
            String [] ids = strIds.split(",");
            for (String id : ids){
                if  (StringUtil.isNotBlank(id)){
                    idList.add(Integer.valueOf(id));
                }
            }
        }
        return idList;
    }

    public static String randomString(int length){
        String str = "ABCDEFGHJKMNPQRSTWXYZabcdefghijkmnprstwxyz2345678";
        int max = str.length();
        Random random = new Random();//随机类初始化
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(max);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
